FeaturedProfilesPortlet = Class.extend({
	init: function()	{
		this.name = "FeaturedProfilesPortlet";
	},
	
	run: function()	{
		var obj = this;
		this.onAjax('ajax', 'get-search-dynamic', {
			'search-page':1, 'rows':7, 'type':'person-best', 'query':'*:*'
		}, 'GET', {
			'onSuccess': function(ret)	{
				ret = $.parseJSON(ret);
				var docs = ret.response.docs;
				obj.model = {};
				obj.model.users = Array();
				//shuffle
				var shuffled = Array();
				for(var i=0;i<5;i++)	{
					var rand = Math.floor(Math.random()*docs.length);
					shuffled.push(docs[rand]);
					docs.splice(rand, 1);
				}
				
				for(var i=0;i<shuffled.length;i++)	{
					var expertises = Array();
					if (shuffled[i].expertise != undefined)	{
						for(var j=0;j<shuffled[i].expertise.length && j<2;j++)	{
							expertises.push(shuffled[i].expertise[j]);
						}
					}
					obj.model.users.push({id: shuffled[i].profile_id, name:shuffled[i].full_name, expertise:expertises, avatar: shuffled[i].avatar});
				}
				obj.getPortletPlaceholder().paintCanvas(obj.render());
			}
		}, true, 900000);
	}
}).implement(PortletInterface).implement(RenderInterface).implement(AjaxInterface);